home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / sMovPlatform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  1.8 KB  |  86 lines  |  [TEXT/KAHL]

  1. /* Platform sprite, moveable version, not faceless */
  2. /* */
  3.  
  4. #include "SAT.h"
  5. #include "myPlatform.h"
  6.  
  7. FacePtr    platFace;
  8.  
  9. void InitMovPlatform()
  10. {
  11.     platFace = GetFace(138);
  12. }
  13.  
  14. pascal void SetupMovPlatform(SpritePtr me)
  15. {
  16.     Rect            r;
  17.     PolyHandle    pol;
  18.     
  19.     me->speed.v =-1 + Rand(2) * 2;
  20.     me->face = platFace; 
  21.     SetRect(&me->hotrect, 0, 3, 60, 20);
  22. }
  23.  
  24. pascal void HandleMovPlatform(SpritePtr me)
  25. {
  26.     me->position.v +=  me->speed.v;
  27.     if(me->position.v < 40)
  28.         me->speed.v =1;
  29.     if(me->position.v > offSizeV - 32)
  30.         me->speed.v =-1;
  31.  
  32.     if(me->speed.v == 0){
  33.         if(me->position.v > offSizeV/2)
  34.             me->speed.v = -1;
  35.         else
  36.             me->speed.v = 1;
  37.     }
  38.     me->layer = -1*(me->position.v);
  39.  
  40. }
  41.  
  42. pascal void HitMovPlatform(SpritePtr me, SpritePtr him)
  43. {
  44.     int    mini, i, min;
  45.     int    diff[5];
  46.         
  47.     if(him->task != HandlePlatform) {
  48.         diff[1] =-me->hotrect2.top + (him->hotrect2.bottom);        /* TtoB */
  49.         diff[2] =-him->hotrect2.top + (me->hotrect2.bottom);        /* BtoT */
  50.         diff[3] =-me->hotrect2.left + (him->hotrect2.right);            /* LtoR */
  51.         diff[4] =-him->hotrect2.left + (me->hotrect2.right);            /* RtoL */
  52.         mini = 0;
  53.         min = 10000;
  54.         for(i =1; i <= 4; i++)
  55.             if(min > diff[i]){
  56.                 min = diff[i];
  57.                 mini = i;
  58.             }
  59.         switch(mini){
  60.             case    1: 
  61.                     him->position.v = him->position.v - diff[1] + 2;  
  62.                     him->kind =10; 
  63.                     if(him->speed.v > 0)
  64.                         him->speed.v = 0;
  65.                     break;
  66.             case 2: 
  67.                     him->position.v = him->position.v + diff[2] + 1;
  68.                     if(him->speed.v < 0)
  69.                         him->speed.v = (him->speed.v)*(-1);
  70.                     break;
  71.             case 3: 
  72.                     him->position.h = him->position.h - diff[3] - 1;
  73.                     him->kind =10; 
  74.                     if(him->speed.h > 0)
  75.                         him->speed.h = (him->speed.h)*(-1);
  76.                     break;
  77.             case 4: 
  78.                     him->position.h =him->position.h + diff[4] + 1;
  79.                     him->kind =10; 
  80.                     if(him->speed.h < 0)
  81.                         him->speed.h = (him->speed.h)*(-1);
  82.                     break;
  83.         } /* switch */
  84.     }  /* if */
  85. }
  86.